package com.itheima.service.sms.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.core.model.PageResult;
import com.itheima.common.utils.StringUtils;
import com.itheima.mapper.sms.SmsCouponHistoryMapper;
import com.itheima.pojo.sms.SmsCouponHistory;
import com.itheima.service.sms.SmsCouponHistoryService;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService
public class SmsCouponHistoryServiceImpl
        extends ServiceImpl<SmsCouponHistoryMapper, SmsCouponHistory>
    implements SmsCouponHistoryService
{
    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param orderSn
     * @param couponId
     * @param pageNum
     * @param pageSize
     * @param useStatus
     * @return
     */
    @Override
    public PageResult selectAll(String orderSn, Integer couponId, Integer pageNum, Integer pageSize, Integer useStatus) {
        //构造分页构造器
        Page<SmsCouponHistory> pageInfo=new Page<>(pageNum,pageSize);

        //构造条件构造器
        LambdaQueryWrapper<SmsCouponHistory> lqw =new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(orderSn),SmsCouponHistory::getOrderSn,orderSn);
        lqw.eq(useStatus!=null,SmsCouponHistory::getUseStatus,useStatus);
        lqw.eq(couponId!=null,SmsCouponHistory::getCouponId,couponId);

        this.page(pageInfo,lqw);

        return PageResult.init((int) pageInfo.getTotal(), pageSize, pageNum, pageInfo.getRecords());
    }
}
